package com.dd.cloud.user.service.phar.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dd.cloud.user.entity.phar.PharmacyRelatedProvince;
import com.dd.cloud.common.interceptor.UserInterceptor;
import com.dd.cloud.user.mapper.phar.PharmacyRelatedProvinceMapper;
import com.dd.cloud.user.res.phar.PharmacyChooseRes;
import com.dd.cloud.user.service.phar.IPharmacyChooseService;
import com.dd.cloud.user.service.phar.IPharmacyRelatedProvinceService;
import com.dd.cloud.common.vo.LoginInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 省市区对应的药房 服务实现类
 * </p>
 *
 * @author czg
 * @since 2022-11-25
 */
@Service
public class PharmacyRelatedProvinceServiceImpl extends ServiceImpl<PharmacyRelatedProvinceMapper, PharmacyRelatedProvince> implements IPharmacyRelatedProvinceService {
    @Autowired
    private IPharmacyChooseService pharmacyChooseService;

    /**
     * 获取机构对应的药房
     *
     * @param mechanId
     * @return
     */
    @Override
    public PharmacyRelatedProvince getPharRelatedMechan(Integer mechanId) {
        LoginInfo loginInfo = UserInterceptor.getLoginUserInfo(LoginInfo.UserType.DOCTOR).get();
        PharmacyRelatedProvince res = new PharmacyRelatedProvince();
        if (mechanId == null) {
            mechanId = loginInfo.getMechanId();
        }
        List<PharmacyChooseRes> chooseList = pharmacyChooseService.getPharChooseListByMechan(mechanId);
        for (PharmacyChooseRes item : chooseList) {
            if (item.getChoose() == 1) {
                res.setPharId(item.getPharId());
            }
        }
        return res;
    }
}
